<template>
  <el-dialog title="分配角色" :visible.sync="isShow" @close="closeEvent">
    <!--
          el-checkbox
             值(选中该项后的值)：label
             内容：默认插槽显示
             v-model:双向绑定后的值   value  @input
                 v-model的值如果是数组，选中某项后它的值就会添加到数组中，如果是非数组，它的值最终会转换成boolean值，选中某项。所有项都选中

       -->
    <!-- <h3>{{ checkValue }}</h3> -->
    <el-checkbox-group v-model="checkValue">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">确定</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import { sysRole } from '@/api/setting.js'
import { sysUser } from '@/api/user.js'
import { sysUserAssignRoles } from '@/api/employees'
export default {
  data() {
    return {
      isShow: false,
      checkValue: [],
      list: [],
      id: ''
    }
  },
  async created() {
    const res = await sysRole({ page: 1, pagesize: 999 })
    this.list = res.data.rows
    console.log('所有的角色列表', res)
  },
  methods: {
    // 弹框关闭时触发
    closeEvent() {
      this.isShow = false
      // 关闭弹框时清除勾选项
      this.checkValue = []
    },
    async getRoleIds(id) {
      this.id = id
      const res = await sysUser(id)
      this.checkValue = res.data.roleIds || []
      console.log('获取当前帐号的角色信息', res)
    },
    // 确定点击，
    async submit() {
      await sysUserAssignRoles(this.id, this.checkValue)
      this.$message.success('分配角色成功')
      this.closeEvent()
    }
  }
}
</script>
<style></style>
